package cn.edu.lingnan.fruitshop.controller;


import cn.edu.lingnan.fruitshop.common.JSONResult;
import cn.edu.lingnan.fruitshop.pojo.Address;
import cn.edu.lingnan.fruitshop.service.AddressService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpSession;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author 张小凡
 * @since 2022-01-04
 */
@Controller
@RequestMapping("/address")
public class AddressController {
    @Autowired
    private AddressService addressService;

    /**
     * 商户更改自己的address信息
     * @param address
     * @param session
     * @return
     */
    @GetMapping("/sellerUpdateAddressInfo")
    @ResponseBody
    public JSONResult<Void> sellerUpdateAddressInfo(Address address, HttpSession session){
        return addressService.sellerUpdateAddressInfo(address,session);
    }

    @RequestMapping("/setDefault")
    public String setDefault(Integer id,HttpSession session){
        return addressService.setDefault(id,session);
    }
    /**
     * 增加收货地址-检查收货人名字
     * @param userName
     * @return
     */
    @GetMapping("/checkAddressConsignee")
    @ResponseBody
    public JSONResult<Void> checkAddressConsignee(String userName){
        return addressService.checkAddressConsignee(userName);
    }

    /**
     *增加收货地址-检查收货地址
     * @param address
     * @return
     */
    @GetMapping("/checkAddressAddress")
    @ResponseBody
    public JSONResult<Void> checkAddressAddress(String address){
        return addressService.checkAddressAddress(address);
    }
    /**
     *增加收货地址-检查手机号码
     * @param phone
     * @return
     */
    @GetMapping("/checkAddressPhone")
    @ResponseBody
    public JSONResult<Void> checkAddressPhone(String phone){
        return addressService.checkAddressPhone(phone);
    }
    /**
     * 增加收货地址
     * @param address
     * @return
     */
    @GetMapping("/addAddress")
    @ResponseBody
    public JSONResult<Void> addAddress(Address address,HttpSession session){
        return addressService.addAddress(address, session);
    }
    @RequestMapping("/deleteAdmin")
    public String deleteAdmin(Integer id){
        return addressService.deleteAdmin(id);
    }
    @RequestMapping("/updateAdmin")
    public String updateAdmin(Address address){
        return addressService.updateAdmin(address);
    }
}

